/*
 * measure1.cpp
 *
 *  Created on: 2016年6月13日
 *      Author: guyadong
 */
#include <cmath>
#include "measure.h"
#include "assert_macros.h"
#include "detect_cl.h"
namespace gdface {
measure::measure():measure(DETECT_WIN_SIZE,DETECT_WIN_SCALE_RATIO,SCALE_SIZE){}
measure::measure(size_t min_detect_win_size, float step, size_t scale_size) :
		min_detect_win_size(min_detect_win_size), step(step), log_step(std::log(step)) {
	throw_if(step <= 1.0f || 0 == scale_size)
	detect_win_size = std::vector<size_t>(scale_size);
	detect_win_pixels_sum = std::vector<size_t>(scale_size);
	scale_ratio = std::vector<float>(scale_size);
	for (decltype(detect_win_size.size()) i = 0; i < detect_win_size.size(); ++i) {
		scale_ratio[i] = float(pow(step, i));
		detect_win_size[i] = size_t(min_detect_win_size * scale_ratio[i] + DETECT_WIN_SCALE_COMP);
		detect_win_pixels_sum[i] = detect_win_size[i] * detect_win_size[i];
	}
}
size_t measure::get_detect_win_size_by_index(size_t index) const {
	try {
		return detect_win_size.at(index);
	} catch (std::out_of_range&) {
		return size_t(min_detect_win_size * std::pow(double(step), index) + 0.5);
	}
}
size_t measure::operator [](size_t index) {
	return get_detect_win_size_by_index(index);
}

int measure::index_of_measure_floor(size_t s) const {
	return int(std::floor(std::log(float(s) / this->min_detect_win_size) / this->log_step));
}

int measure::index_of_measure_ceil(size_t s) const {
	return int(std::ceil(std::log(float(s) / this->min_detect_win_size) / this->log_step));
}
const measure global_measure(DETECT_WIN_SIZE, DETECT_WIN_SCALE_RATIO,30);
/*
 * 初始化全局对象global_measure
 * */
void init_global_measure(size_t scale_size, float step, size_t min_detect_win_size){
	const_cast<measure&>(global_measure)=measure (min_detect_win_size, step, scale_size);
}
} /* namespace gdface */
